|
|
|
|
|
|
|
SQLVBMain.lblProgress = "Creating Relations..."
DoEvents
'
' if it has spaces, add braces
If InStr(cTable, " ") <> 0 Then
cTable = "[" + cTable + "]"
End If
If InStr(cForgTable, " ") <> 0 Then
cForgTable = "[" + cForgTable + "]"
End If
'
' create array of field name/foriegn names
x = 0
For Each fldObject In relObject.Fields
ReDim Preserve cFields(x + 1, 2) As String
cFields(x, 1) = fldObject.Name
cFields(x, 2) = fldObject.ForeignName
x = x + 1
Next
'
cTemp = "// create relation " + relObject.Name + EOL
cTemp = cTemp + "ALTER TABLE " + cForgTable
cTemp = cTemp + " ADD CONSTRAINT " + relObject.Name + EOL
'
' write out local table fields
cTemp = cTemp + Space(INDENT) + "FOREIGN KEY ("
For z = 0 To x - 1
cTemp = cTemp + cFields(z, 2) + ","
Next
cTemp = Left(cTemp, Len(cTemp) - 1) + ") "
'
' write out foreign table/fields
cTemp = cTemp + "REFERENCES " + cTable + "("
For z = 0 To x - 1
cTemp = cTemp + cFields(z, 1) + ","
Next
cTemp = Left(cTemp, Len(cTemp) - 1) + ");" + EOL
'
wrCreateRelation = cTemp
'
End Function |
|
|
|
|
|
|
|
|
This is much like the index routine. Any definition that has ''MSYS" as part of either table (left or right) is ignored. Notice that the Fields collection must be traversed for relation objects, too. |
|
|
|
|
|
|
|
|
That's the end of the generate portion of the script. Next you add the object interface for use as an OLE Server. |
|
|
|
|
|